﻿<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
<link href="../css/bootstrap.min.css" rel="stylesheet" />
<link href="../css/font-awesome.min.css" rel="stylesheet" />
<link href="../js/plugins/layer/skin/layer.css" rel="stylesheet" />
<link href="../js/plugins/layer/skin/layer.ext.css" rel="stylesheet" />
<script src="../js/jquery-2.1.1.min.js"></script>
<script src="../js/plugins/layer/layer.min.js"></script>
<script src="../js/plugins/linq/linq.js"></script>
<script src="../weixin/js/common.js"></script>
<script src="../js/tableToExcel.js"></script>
<style>
    table {
        font-size: 15px;
        height: auto;
        width: auto;
        text-align: center!important;
    }
    table th {
        text-align: center!important;
        min-width: 100px;
        background-color: darkgrey;
    }
    .market{
        background-color: lightyellow;
    }
    .otherData {
        background-color: #c5d9f1;
    }
    .clossing {
        background-color: #f2dcdb;
    }
    .saleBillPartQty {
        background-color: #dcffd9;
    }
    .kpiQty {
        background-color: #fde9d9;
    }
    .nowData {
        background-color: #b7dee8;
    }
</style>
<html>
<head>
    <title>分部时段跟踪报表</title>
</head>
<body>
<div style="margin-top: 5px; margin-left: 5px">
    <a class='btn btn-success btn-xs btn-info' onclick='tableToExcelMethod(exportReport)'>导出</a>
    <table border="1" id="exportReport">
        <thead id="exTable_head">
        </thead>
        <tbody id="exTable_body">
        </tbody>
    </table>
</div>
</body>
</html>

<script type="text/javascript">
    $(function() {
        loadData();
    });
    
    var loadData = function () {
        $.post("VendCustHandler.ashx",
            {
                "action": "GetVendCustSalesReport",
                "vendCustID": 1,
                "periodYear": 1,
                "startDate": "2017-11-11",
                "endDate": "2017-11-11",
            },
            function (data) {
                var exTBody = $("#exTable_body");
                var exTHead = $("#exTable_head");

                if (data.Success == true) {

                    var exThMark = "<tr>";
                    exThMark += "<th>货号</th><th>供应商</th><th>范围</th><th>售罄率</th><th>销售金额</th><th>销售数量</th><th>成本价</th><th>当前仓存</th><th>当前店存</th>";
                    exThMark += "</tr>";
                    exTHead.empty();
                    exTHead.append(exThMark);
                    console.log(data.Data);
                    if (data.Data.resultTotalList.length > 0) {
                        
                        var exTbHtml = "";
                        console.log(data.Data.resultTotalList);
                        data.Data.resultTotalList.map(function (rtOutLi) {

                            var exOutTBody = "<tr>";

                            exOutTBody += "<td>" + rtOutLi.MaterialID + "（" + rtOutLi.ColorName + "）</td>";
                            exOutTBody += "<td>" + rtOutLi.VendCustName + "</td>";
                            exOutTBody += "<td>" + rtOutLi.DataText + "</td>";
                            exOutTBody += "<td>" + (Y.checkNull(rtOutLi.SaleRate) ? '0.00' : (rtOutLi.SaleRate * 100).toFixed(2)) + "%</td>";
                            exOutTBody += "<td>" + (Y.checkNull(rtOutLi.SaleAmount) ? '0.00' : rtOutLi.SaleAmount.toFixed(2)) + "</td>";
                            exOutTBody += "<td>" + rtOutLi.SaleQty + "</td>";
                            exOutTBody += "<td>" + (Y.checkNull(rtOutLi.CostPrice) ? '0.00' : rtOutLi.CostPrice.toFixed(2)) + "</td>";
                            exOutTBody += "<td>" + rtOutLi.StockQty + "</td>";
                            exOutTBody += "<td>" + rtOutLi.ShopQty + "</td>";

                            exOutTBody += "</tr>";

                            exTbHtml += exOutTBody;

                            if (rtOutLi.resultTotalProvList.length > 0) {

                                var exInTHead = "<tr>";
                                exInTHead =
                                    "<td></td><td>省份</td><td>仓库/店铺</td><td>售罄率</td><td>销售金额</td><td>销售数量</td><td>当前库存</td><td></td><td></td>";
                                exTbHtml += exInTHead;
                                console.log(data.Data.resultTotalProvList);
                                rtOutLi.resultTotalProvList.map(function (rtInList) {

                                    var rtInListLength = rtInList.length;
                                    if (rtInListLength == 3) {
                                        debugger;
                                    }
                                    var exInTBody = "<tr>";
                                    exInTBody += "<td rowspan='" + rtInListLength + "'></td>";
                                    exInTBody += "<td rowspan='" + rtInListLength + "'>" + rtInList[0].Province + "</td>";
                                    
                                    rtInList.map(function (rtInLi, index) {
                                        if (index > 0) {
                                            exInTBody += "<tr>";
                                        }
                                        exInTBody += "<td>" + rtInLi.DataText + "</td>";
                                        exInTBody += "<td>" + (Y.checkNull(rtInLi.SaleRate) ? '0.00' : (rtInLi.SaleRate * 100).toFixed(2)) + "%</td>";
                                        exInTBody += "<td>" + (Y.checkNull(rtInLi.SaleAmount) ? '0.00' : rtInLi.SaleAmount.toFixed(2)) + "</td>";
                                        exInTBody += "<td>" + rtInLi.SaleQty + "</td>";
                                        exInTBody += "<td>" + rtInLi.Qty + "</td>";

                                        if (index == 0) {
                                            exInTBody += "<td rowspan='" + rtInListLength + "'></td><td rowspan='" + rtInListLength + "'></td></tr>";
                                        } else {
                                            exInTBody += "</tr>";
                                        }

                                    });
                                    exTbHtml += exInTBody;

                                });
                            }

                        });

                        exTBody.empty();
                        exTBody.append(exTbHtml);
                    } else {
                        exTHead.empty();
                        exTHead.append(exThMark);
                        var emptyTable = "<tr><td colspan='9'>暂无数据</td></tr>";
                        exTBody.empty();
                        exTBody.append(emptyTable);
                    }
                }
            });
    }

</script>

